package tests;

import static org.junit.Assert.*;
import model.ConversionMethods;
import model.Job;

import org.junit.Test;

import controller.Controller;

public class ConversionMethodsTest {

	ConversionMethods cm = new ConversionMethods(new Controller());

	@Test
	public void calculateAACTest() {

		// Eingegebene Werte
		String[] test0 = {};
		String[] test1 = { "SCE" };
		String[] test2 = { "AIS", "AIS", "SCE", "RCS" };
		String[] test3 = { "CSE", "CES", "CES", "DER" };
		String[] test4 = { "RCS", "SCE" };
		String[] test5 = { "ISR", "ISA", "RAE", "IRE", "ECS", "ASE", "CER",
				"AIR" };

		// Erwartete Werte
		String str0 = "";
		String str1 = "SCE";
		String str2 = "ASI";
		String str3 = "CES";
		String str4 = "CSR";
		String str5 = "IAR";

		// Tests
		assertEquals(str0,
				ConversionMethods.calculateAverageAspirationCode(test0));
		assertEquals(str1,
				ConversionMethods.calculateAverageAspirationCode(test1));
		assertEquals(str2,
				ConversionMethods.calculateAverageAspirationCode(test2));
		assertEquals(str3,
				ConversionMethods.calculateAverageAspirationCode(test3));
		assertEquals(str4,
				ConversionMethods.calculateAverageAspirationCode(test4));
		assertEquals(str5,
				ConversionMethods.calculateAverageAspirationCode(test5));

	}

	@Test
	public void fieldToStringTest() {
		Job job0 = null;
		Job job1 = new Job("Arzt/Ärztin", "", "SCE", "_ARZ");
		Job job2 = new Job("Gärtner/in", "", "AIS", "_GÄ");
		Job job3 = new Job("Kosmetiker/in", "", "SAI", "_KOS");
		Job job4 = new Job("Schauspieler/in", "", "RCS", "_SCH");
		Job job5 = new Job("Polizist/in", "", "ISA", "_POL");
		Job job6 = new Job("Maurer/in", "", "RCS", "_MAU");

		Job[][] test0 = {};
		Job[][] test1 = { { job0 } };
		Job[][] test2 = { { job1 } };
		Job[][] test3 = { { job2, job1 }, { job4 } };
		Job[][] test4 = { { job0, job6 }, { job5, job4, job3 } };
		Job[][] test5 = { { job0, job0 }, { job5 }, { job3, job2 } };

		// Erwartete Werte
		String str0 = "";
		String str1 = "null$";
		String str2 = "Arzt/Ärztin$";
		String str3 = "Gärtner/in$Arzt/Ärztin$Schauspieler/in$";
		String str4 = "null$Maurer/in$Polizist/in$Schauspieler/in$Kosmetiker/in$";
		String str5 = "null$null$Polizist/in$Kosmetiker/in$Gärtner/in$";

		// Tests
		assertEquals(str0, ConversionMethods.fieldToString(test0));
		assertEquals(str1, ConversionMethods.fieldToString(test1));
		assertEquals(str2, ConversionMethods.fieldToString(test2));
		assertEquals(str3, ConversionMethods.fieldToString(test3));
		assertEquals(str4, ConversionMethods.fieldToString(test4));
		assertEquals(str5, ConversionMethods.fieldToString(test5));

	}

	@Test
	public void containsJobTest() {
		Job job1 = new Job("Arzt/Ärztin", "", "SCE", "_ARZ");
		Job job2 = new Job("Gärtner/in", "", "AIS", "_GÄ");
		Job job3 = new Job("Kosmetiker/in", "", "SAI", "_KOS");
		Job job4 = new Job("Schauspieler/in", "", "RCS", "_SCH");
		Job job5 = new Job("Polizist/in", "", "ISA", "_POL");
		Job job6 = new Job("Polizist/in", "", "", "");
		Job job7 = new Job("Maurer/in", "", "RCS", "_MAU");

		Job[][] test1 = { { job1, job2 } };
		Job[][] test2 = { { job1, job2 }, { job3, job1 } };
		Job[][] test3 = { { job1, job6 }, { job3, job5 } };
		Job[][] test4 = { { job3, job4, job1 }, { job2, job7, job5 } };
		Job[][] test5 = { { job1, job3, job2 }, { job2, job7, job5 }, { job6 } };

		// Erwartete Werte
		int[] result0 = { -1, -1 };
		int[] result1 = { 0, 0 };
		int[] result2 = { 0, 1 };
		int[] result3 = { 1, 0 };
		int[] result4 = { 1, 1 };
		int[] result5 = { 1, 2 };
		int[] result6 = { 2, 0 };

		// Tests
		assertArrayEquals(result1, ConversionMethods.containsJob(job1, test1));
		assertArrayEquals(result2, ConversionMethods.containsJob(job2, test1));
		assertArrayEquals(result0, ConversionMethods.containsJob(job3, test1));
		assertArrayEquals(result3, ConversionMethods.containsJob(job3, test2));
		assertArrayEquals(result4, ConversionMethods.containsJob(job5, test3));
		assertArrayEquals(result5, ConversionMethods.containsJob(job5, test4));
		assertArrayEquals(result0, ConversionMethods.containsJob(job6, test4));
		assertArrayEquals(result6, ConversionMethods.containsJob(job6, test5));
	}

	@Test
	public void stringToJobArrayTest() {
		String test0 = null;
		String test1 = "Landwirt/in$";
		String test2 = "Maurer/in$null$Archäologe/in$";
		String test3 = "null$null$null$null$null$null$null$null$null$null$null$Infor#matiker/in$null$null$null$null$null$null$Physiker/+in$null$null$Ingenieur/+in +Elektrotechnik$null$Berufs#sportler/in$null$null$null$Mathe#matiker/in$null$null$null$null$null$Fachinfor#matiker/in +(AE)$null$null$null$Arzt/+Ã„rztin$null$null$null$null$null$null$null$null$null$null$null$Biologe/+Biologin$null$null$null$null$null$null$null$null$null$null$null$SÃ¤nger/in$Alten#pfleger/in$null$null$null$null$null$null$null$null$null$null$null$null$null$null$null$null$null$Steward/+Stewardess$";

		// Erwartete Werte
		String varAdd0 = "_INF";
		String varAdd1 = "_PHY";
		String varAdd2 = "_ELT";

		// Tests
		assertNull(cm.stringToJobArray(test0));
		assertNull(cm.stringToJobArray(test1));
		assertNull(cm.stringToJobArray(test2));
		assertNull(cm.stringToJobArray(test3)[0][0]);
		assertEquals(varAdd0,
				cm.stringToJobArray(test3)[1][2].getVariableAdding());
		assertEquals(varAdd1,
				cm.stringToJobArray(test3)[2][0].getVariableAdding());
		assertNotSame(varAdd2,
				cm.stringToJobArray(test3)[1][2].getVariableAdding());

	}

	@Test
	public void intArrayToStringTest() {
		int[][] test0 = {};
		int[][] test1 = { { 1 } };
		int[][] test2 = { { 0, 1, -1 }, { -1, 0, 0 }, { 1, 1, -1 } };
		int[][] test3 = { { -1, -1, -1, -1 }, { 0, 0, 1, 1 }, { 0 }, { 1, 0 } };

		// Erwartete Werte
		String str0 = "";
		String str1 = "1";
		String str2 = "01-1-10011-1";
		String str3 = "-1-1-1-10011010";

		// Tests
		assertEquals(str0, ConversionMethods.intArrayToString(test0));
		assertEquals(str1, ConversionMethods.intArrayToString(test1));
		assertEquals(str2, ConversionMethods.intArrayToString(test2));
		assertEquals(str3, ConversionMethods.intArrayToString(test3));
	}

	@Test
	public void stringToIntArrayTest() {
		String test0 = null;
		String test1 = "-1-1-1-100110" + "11111100-1" + "1100-1-1011"
				+ "-1-1-1-1-10000" + "111111110" + "0011-1-100-1"
				+ "00-1-111-1-1-1" + "111-1-1-100-1" + "1-1-1-1-10000";
		String test2 = "-10";

		// Erwartete Werte
		int[][] array0 = { { -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 },
				{ -1, -1, -1, -1, -1, -1, -1, -1, -1 } };
		int[][] array1 = { { -1, -1, -1, -1, 0, 0, 1, 1, 0 },
				{ 1, 1, 1, 1, 1, 1, 0, 0, -1 },
				{ 1, 1, 0, 0, -1, -1, 0, 1, 1 },
				{ -1, -1, -1, -1, -1, 0, 0, 0, 0 },
				{ 1, 1, 1, 1, 1, 1, 1, 1, 0 },
				{ 0, 0, 1, 1, -1, -1, 0, 0, -1 },
				{ 0, 0, -1, -1, 1, 1, -1, -1, -1 },
				{ 1, 1, 1, -1, -1, -1, 0, 0, -1 },
				{ 1, -1, -1, -1, -1, 0, 0, 0, 0 } };

		// Tests
		assertArrayEquals(array0, cm.stringToIntArray(test0));
		assertArrayEquals(array1, cm.stringToIntArray(test1));
		assertNull(cm.stringToIntArray(test2));

	}

	@Test
	public void evaluationToStringTest() {
		String str0 = "";
		String str1 = "RCS";
		String str2 = "AIS";

		int[] value0 = {};
		int[] value1 = { 0, -1, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, 0,
				0, 0, 0, 1, 1, 1, -1, -1, 0, 0, 1, 1 };

		// Erwartete Werte
		String result0 = "";
		String result1 = "RCS0-1100-1-1-101110-1-10000111-1-10011";
		String result2 = "AIS0-1100-1-1-101110-1-10000111-1-10011";
		String result3 = "0-1100-1-1-101110-1-10000111-1-10011";

		// Tests
		assertEquals(result0,
				ConversionMethods.evaluationToString(value0, str0));
		assertEquals(result1,
				ConversionMethods.evaluationToString(value1, str1));
		assertEquals(result2,
				ConversionMethods.evaluationToString(value1, str2));
		assertEquals(result3,
				ConversionMethods.evaluationToString(value1, str0));
	}

	@Test
	public void stringToEvaluation() {
		// Eingegebene Werte
		String value0 = null;
		String value1 = "AIS0-1100-1-1-101110-1-10000111-1-10011";
		String value2 = "SAI-1-1-101-1-1-101110-1-10-100111-1-10011";
		String value3 = "RCS00";
		String value4 = "C0-1100-1-1-101110-1-10000111-1-10011";
		String value5 = "RCS-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-100000";
		String value6 = "RC--1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-100000";

		// Erwartete Werte
		Object[] result0 = { "", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
				-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
				-1 };
		Object[] result1 = { "AIS", 0, -1, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0,
				-1, -1, 0, 0, 0, 0, 1, 1, 1, -1, -1, 0, 0, 1, 1 };
		Object[] result2 = { "SAI", -1, -1, -1, 0, 1, -1, -1, -1, 0, 1, 1, 1,
				0, -1, -1, 0, -1, 0, 0, 1, 1, 1, -1, -1, 0, 0, 1, 1 };

		// Tests
		assertArrayEquals(result0, ConversionMethods.stringToEvaluation(value0));
		assertArrayEquals(result0, ConversionMethods.stringToEvaluation(value3));
		assertArrayEquals(result0, ConversionMethods.stringToEvaluation(value4));
		assertArrayEquals(result0, ConversionMethods.stringToEvaluation(value5));
		assertArrayEquals(result0, ConversionMethods.stringToEvaluation(value6));
		assertArrayEquals(result1, ConversionMethods.stringToEvaluation(value1));
		assertArrayEquals(result2, ConversionMethods.stringToEvaluation(value2));

	}

	@Test
	public void getIntArrayFromEvaluationTest() {
		// Eingegebene Werte
		Object[] test1 = {};
		Object[] test2 = { "SAI", -1, -1, -1, 0, 1, -1, -1, -1, 0, 1, 1, 1, 0,
				-1, -1, 0, -1, 0, 0, 1, 1, 1, -1, -1, 0, 0, 1, 1 };
		Object[] test3 = { "RCS", -1, -1, -1, 0, 1, -1, -1, -1, 0, 1, 1, 1, 0,
				-1, -1, 0, -1, 0, 0, 1, 1, 1, -1, -1, 0, 0, 1, 1, 1 };

		// Erwartete Werte
		int[] result1 = { -1, -1, -1, 0, 1, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1,
				0, -1, 0, 0, 1, 1, 1, -1, -1, 0, 0, 1, 1 };

		// Tests
		assertNull(ConversionMethods.getIntArrayFromEvaluation(test1));
		assertNull(ConversionMethods.getIntArrayFromEvaluation(test3));
		assertArrayEquals(result1,
				ConversionMethods.getIntArrayFromEvaluation(test2));

	}
}
